
#ifndef _SUB_H_
#define _SUB_H_

typedef struct _stack{
	int item_len;
	int item_num;
	int stack_size;
	char *p;
}stack_t;

int stack_create( void * pool, stack_t *stack, int item_len );
int stack_push( void * pool, stack_t *stack, char *data );
int stack_pop( void * pool, stack_t *stack, char *data );
int stack_free( void * pool, stack_t *stack );
int stack_get( void * pool, stack_t *stack, int idx, char *data );
int stack_set( void * pool, stack_t *stack, int idx, char *data );
int stack_reverse( void * pool, stack_t *dst, stack_t *src );


////
#define POOL_EXF_SIZE	128
#define POOL_ATOM_NUM	10
#define POOL_PTR_SIZE	(sizeof(void*))
#define POOL_BLK_SIZE	(sizeof(pool_block_t))

typedef struct _pool_block{
	int size;
	char exinfo[POOL_EXF_SIZE];		//for debug
	void * data;
	struct _pool_block * next;
	struct _pool_block * pre;
}pool_block_t;

typedef struct _pool{
	int num_all;
	int num_free;
	pool_block_t * list_all;
	pool_block_t * list_free[POOL_ATOM_NUM];
}pool_t;


pool_t * pool_create();
void pool_delete( pool_t * pool );
void * pool_malloc( pool_t * pool, int sz, char * exinfo );
void pool_free( pool_t * pool, void * ptr );


////
#define HH_TAB_SIZE	128

typedef struct _hh_node{
	unsigned int hash, klen, dlen;
	void * key;
	void * data;
	struct _hh_node *next;
}hh_node_t;

typedef struct _hh_head{
	unsigned int node_num;
	hh_node_t *  node_list;
}hh_head_t;

typedef struct _hh_opts{
	int (*cmp_key)(void *key1, void *key2);
	unsigned int (*get_hash)(void *key);
	void * (*new_key)( void *, int);
	void * (*new_data)( void *, int);
	void (*del_key)( void *, void *key);
	void (*del_data)(void *, void *data);
}hh_opts_t;

typedef struct _hh_hash{
	hh_opts_t opts;
	hh_head_t tabs[HH_TAB_SIZE];
}hh_hash_t;

hh_hash_t * hh_create();
int hh_add_node( pool_t * pool, hh_hash_t * phh, void *key, int klen, void *data, int dlen );
int hh_get_node( hh_hash_t * phh, void *key, void *data );
int hh_free( pool_t * pool, hh_hash_t * phh );


#endif

